package com.sc.nft.dao;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.Role;
import com.sc.nft.mapper.RoleMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

/**
 * 角色表(pro_role)数据DAO
 *
 * @author zhangxiangyu
 * @since 2022-02-02 17:11:20
 * @description 
 */
@Slf4j
@Repository
public class RoleDao extends ServiceImpl<RoleMapper, Role> {



    public Role selectByRoleName(String roleName){
        QueryWrapper<Role> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("role_name",roleName);
        queryWrapper.eq("is_delete",Boolean.FALSE);
        return baseMapper.selectOne(queryWrapper);
    }

    public Page<Role> queryLikeRoleName(String roleName, long pageNo, long pageSize){

        QueryWrapper<Role> queryWrapper = new QueryWrapper<>();
        if(StrUtil.isNotBlank(roleName)){
            queryWrapper.like("role_name",roleName);
        }
        queryWrapper.eq("is_delete",Boolean.FALSE);
        queryWrapper.orderByDesc("id");

        return baseMapper.selectPage(new Page<>(pageNo,pageSize),queryWrapper);

    }
}